package com.core.sdk.extra.weather;

import java.lang.reflect.Type;

import org.apache.http.client.methods.HttpUriRequest;

import roboguice.util.RoboAsyncTask;
import android.content.Context;

import com.core.sdk.utils.HttpUtil;
import com.core.sdk.utils.HttpUtil.ParamSendType;
import com.google.gson.reflect.TypeToken;

public class WeatherDetailLoadTask extends RoboAsyncTask<WeatherDetailInfo> {
	private final String tag = this.getClass().getSimpleName();

	private String cityId =null;
	private final String baseUrl = "http://m.weather.com.cn/data/%s.html";
	public WeatherDetailLoadTask(Context context,String cityId) {
		super(context);
		this.cityId = cityId;
	}

	@Override
	public WeatherDetailInfo call() throws Exception {
		String url = String.format(baseUrl, cityId);
		Type type = new TypeToken<WeatherResponse<WeatherDetailInfo>>(){}.getType();
		HttpUriRequest request = HttpUtil.buildRequest(url, HttpUtil.Method.GET,null,ParamSendType.text);
		WeatherResponse<WeatherDetailInfo> wr = HttpUtil.execute(request,type);
		return wr.getWeatherinfo();
	}

}
